@backstage-community/plugin-badges-backend 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/badges.cjs.js +85 -0
- package/dist/badges.cjs.js.map +1 -0
- package/dist/database/badgesStore.cjs.js +50 -0
- package/dist/database/badgesStore.cjs.js.map +1 -0
- package/dist/index.cjs.js +12 -513
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/lib/BadgeBuilder/DefaultBadgeBuilder.cjs.js +63 -0
- package/dist/lib/BadgeBuilder/DefaultBadgeBuilder.cjs.js.map +1 -0
- package/dist/plugin.cjs.js +44 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/service/router.cjs.js +294 -0
- package/dist/service/router.cjs.js.map +1 -0
- package/dist/types.cjs.js +12 -0
- package/dist/types.cjs.js.map +1 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @backstage-community/plugin-badges-backend
|
|
2
2
|
|
|
3
|
+
## 0.5.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1f907f2: Deprecated `createRouter` and its router options in favour of the new backend system.
|
|
8
|
+
|
|
9
|
+
## 0.5.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b9e206b: Backstage version bump to v1.32.2
|
|
14
|
+
|
|
3
15
|
## 0.5.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var catalogModel = require('@backstage/catalog-model');
|
|
4
|
+
var errors = require('@backstage/errors');
|
|
5
|
+
|
|
6
|
+
function appTitle(context) {
|
|
7
|
+
return context.config.getOptionalString("app.title") || "Backstage";
|
|
8
|
+
}
|
|
9
|
+
function entityUrl(context) {
|
|
10
|
+
const e = context.entity;
|
|
11
|
+
const entityUri = `${e.metadata.namespace || catalogModel.DEFAULT_NAMESPACE}/${e.kind}/${e.metadata.name}`;
|
|
12
|
+
const catalogUrl = `${context.config.getString("app.baseUrl")}/catalog`;
|
|
13
|
+
return `${catalogUrl}/${entityUri}`.toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
const createDefaultBadgeFactories = () => ({
|
|
16
|
+
pingback: {
|
|
17
|
+
createBadge: (context) => {
|
|
18
|
+
if (!context.entity) {
|
|
19
|
+
throw new errors.InputError('"pingback" badge only defined for entities');
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
description: `Link to ${context.entity.metadata.name} in ${appTitle(
|
|
23
|
+
context
|
|
24
|
+
)}`,
|
|
25
|
+
kind: "entity",
|
|
26
|
+
label: context.entity.kind,
|
|
27
|
+
link: entityUrl(context),
|
|
28
|
+
message: context.entity.metadata.name,
|
|
29
|
+
style: context.style || "flat-square",
|
|
30
|
+
color: context.color
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
lifecycle: {
|
|
35
|
+
createBadge: (context) => {
|
|
36
|
+
if (!context.entity) {
|
|
37
|
+
throw new errors.InputError('"lifecycle" badge only defined for entities');
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
description: "Entity lifecycle badge",
|
|
41
|
+
kind: "entity",
|
|
42
|
+
label: "lifecycle",
|
|
43
|
+
link: entityUrl(context),
|
|
44
|
+
message: `${context.entity.spec?.lifecycle || "unknown"}`,
|
|
45
|
+
style: context.style || "flat-square",
|
|
46
|
+
color: context.color
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
owner: {
|
|
51
|
+
createBadge: (context) => {
|
|
52
|
+
if (!context.entity) {
|
|
53
|
+
throw new errors.InputError('"owner" badge only defined for entities');
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
description: "Entity owner badge",
|
|
57
|
+
kind: "entity",
|
|
58
|
+
label: "owner",
|
|
59
|
+
link: entityUrl(context),
|
|
60
|
+
message: `${context.entity.spec?.owner || "unknown"}`,
|
|
61
|
+
style: context.style || "flat-square",
|
|
62
|
+
color: context.color
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
docs: {
|
|
67
|
+
createBadge: (context) => {
|
|
68
|
+
if (!context.entity) {
|
|
69
|
+
throw new errors.InputError('"docs" badge only defined for entities');
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
description: "Entity docs badge",
|
|
73
|
+
kind: "entity",
|
|
74
|
+
label: "docs",
|
|
75
|
+
link: `${entityUrl(context)}/docs`,
|
|
76
|
+
message: context.entity.metadata.name,
|
|
77
|
+
style: context.style || "flat-square",
|
|
78
|
+
color: context.color
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
exports.createDefaultBadgeFactories = createDefaultBadgeFactories;
|
|
85
|
+
//# sourceMappingURL=badges.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badges.cjs.js","sources":["../src/badges.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DEFAULT_NAMESPACE } from '@backstage/catalog-model';\nimport { InputError } from '@backstage/errors';\nimport { Badge, BadgeContext, BadgeFactories } from './types';\n\nfunction appTitle(context: BadgeContext): string {\n return context.config.getOptionalString('app.title') || 'Backstage';\n}\n\nfunction entityUrl(context: BadgeContext): string {\n const e = context.entity!;\n const entityUri = `${e.metadata.namespace || DEFAULT_NAMESPACE}/${e.kind}/${\n e.metadata.name\n }`;\n const catalogUrl = `${context.config.getString('app.baseUrl')}/catalog`;\n return `${catalogUrl}/${entityUri}`.toLowerCase();\n}\n\n/** @public */\nexport const createDefaultBadgeFactories = (): BadgeFactories => ({\n pingback: {\n createBadge: (context: BadgeContext): Badge => {\n if (!context.entity) {\n throw new InputError('\"pingback\" badge only defined for entities');\n }\n return {\n description: `Link to ${context.entity.metadata.name} in ${appTitle(\n context,\n )}`,\n kind: 'entity',\n label: context.entity.kind,\n link: entityUrl(context),\n message: context.entity.metadata.name,\n style: context.style || 'flat-square',\n color: context.color,\n };\n },\n },\n\n lifecycle: {\n createBadge: (context: BadgeContext): Badge => {\n if (!context.entity) {\n throw new InputError('\"lifecycle\" badge only defined for entities');\n }\n return {\n description: 'Entity lifecycle badge',\n kind: 'entity',\n label: 'lifecycle',\n link: entityUrl(context),\n message: `${context.entity.spec?.lifecycle || 'unknown'}`,\n style: context.style || 'flat-square',\n color: context.color,\n };\n },\n },\n\n owner: {\n createBadge: (context: BadgeContext): Badge => {\n if (!context.entity) {\n throw new InputError('\"owner\" badge only defined for entities');\n }\n return {\n description: 'Entity owner badge',\n kind: 'entity',\n label: 'owner',\n link: entityUrl(context),\n message: `${context.entity.spec?.owner || 'unknown'}`,\n style: context.style || 'flat-square',\n color: context.color,\n };\n },\n },\n\n docs: {\n createBadge: (context: BadgeContext): Badge => {\n if (!context.entity) {\n throw new InputError('\"docs\" badge only defined for entities');\n }\n return {\n description: 'Entity docs badge',\n kind: 'entity',\n label: 'docs',\n link: `${entityUrl(context)}/docs`,\n message: context.entity.metadata.name,\n style: context.style || 'flat-square',\n color: context.color,\n };\n },\n },\n});\n"],"names":["DEFAULT_NAMESPACE","InputError"],"mappings":";;;;;AAoBA,SAAS,SAAS,OAA+B,EAAA;AAC/C,EAAA,OAAO,OAAQ,CAAA,MAAA,CAAO,iBAAkB,CAAA,WAAW,CAAK,IAAA,WA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AAa,EAAA,mBAAA;AAAA,QACb,IAAM,EAAA,QAAA;AAAA,QACN,KAAO,EAAA,MAAA;AAAA,QACP,IAAM,EAAA,CAAA,EAAG,SAAU,CAAA,OAAO,CAAC,CAAA,KAAA,CAAA;AAAA,QAC3B,OAAA,EAAS,OAAQ,CAAA,MAAA,CAAO,QAAS,CAAA,IAAA;AAAA,QACjC,KAAA,EAAO,QAAQ,KAAS,IAAA,aAAA;AAAA,QACxB,OAAO,OAAQ,CAAA,KAAA;AAAA,OACjB,CAAA;AAAA,KACF;AAAA,GACF;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendCommon = require('@backstage/backend-common');
|
|
4
|
+
var lodash = require('lodash');
|
|
5
|
+
var uuid = require('uuid');
|
|
6
|
+
|
|
7
|
+
const migrationsDir = backendCommon.resolvePackagePath(
|
|
8
|
+
"@backstage-community/plugin-badges-backend",
|
|
9
|
+
// Package name
|
|
10
|
+
"migrations"
|
|
11
|
+
// Migrations directory
|
|
12
|
+
);
|
|
13
|
+
class DatabaseBadgesStore {
|
|
14
|
+
constructor(db) {
|
|
15
|
+
this.db = db;
|
|
16
|
+
}
|
|
17
|
+
static async create({
|
|
18
|
+
database,
|
|
19
|
+
skipMigrations
|
|
20
|
+
}) {
|
|
21
|
+
const client = await database.getClient();
|
|
22
|
+
if (!database.migrations?.skip && !skipMigrations) {
|
|
23
|
+
await client.migrate.latest({
|
|
24
|
+
directory: migrationsDir
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return new DatabaseBadgesStore(client);
|
|
28
|
+
}
|
|
29
|
+
async getBadgeFromUuid(uuid) {
|
|
30
|
+
const result = await this.db("badges").select("namespace", "name", "kind").where({ uuid }).first();
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
async getBadgeUuid(name, namespace, kind) {
|
|
34
|
+
const result = await this.db("badges").select("uuid").where({ name, namespace, kind }).first();
|
|
35
|
+
let uuid$1 = result?.uuid;
|
|
36
|
+
if (lodash.isNil(uuid$1)) {
|
|
37
|
+
uuid$1 = uuid.v4();
|
|
38
|
+
await this.db("badges").insert({
|
|
39
|
+
uuid: uuid$1,
|
|
40
|
+
name,
|
|
41
|
+
namespace,
|
|
42
|
+
kind
|
|
43
|
+
}).onConflict(["name", "namespace", "kind"]).ignore();
|
|
44
|
+
}
|
|
45
|
+
return { uuid: uuid$1 };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.DatabaseBadgesStore = DatabaseBadgesStore;
|
|
50
|
+
//# sourceMappingURL=badgesStore.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badgesStore.cjs.js","sources":["../../src/database/badgesStore.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n PluginDatabaseManager,\n resolvePackagePath,\n} from '@backstage/backend-common';\nimport { Knex } from 'knex';\nimport { isNil } from 'lodash';\nimport { v4 as uuidv4 } from 'uuid';\n\n/**\n * internal\n * @public\n */\nexport interface BadgesStore {\n getBadgeUuid(\n name: string,\n namespace: string,\n kind: string,\n ): Promise<{ uuid: string }>;\n\n getBadgeFromUuid(\n uuid: string,\n ): Promise<{ name: string; namespace: string; kind: string } | undefined>;\n}\n\nconst migrationsDir = resolvePackagePath(\n '@backstage-community/plugin-badges-backend', // Package name\n 'migrations', // Migrations directory\n);\n\n/**\n * DatabaseBadgesStore\n * @internal\n */\nexport class DatabaseBadgesStore implements BadgesStore {\n private constructor(private readonly db: Knex) {}\n\n static async create({\n database,\n skipMigrations,\n }: {\n database: PluginDatabaseManager;\n skipMigrations?: boolean;\n }): Promise<DatabaseBadgesStore> {\n const client = await database.getClient();\n\n if (!database.migrations?.skip && !skipMigrations) {\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new DatabaseBadgesStore(client);\n }\n\n async getBadgeFromUuid(\n uuid: string,\n ): Promise<{ name: string; namespace: string; kind: string } | undefined> {\n const result = await this.db('badges')\n .select('namespace', 'name', 'kind')\n .where({ uuid: uuid })\n .first();\n\n return result;\n }\n\n async getBadgeUuid(\n name: string,\n namespace: string,\n kind: string,\n ): Promise<{ uuid: string }> {\n const result = await this.db('badges')\n .select('uuid')\n .where({ name: name, namespace: namespace, kind: kind })\n .first();\n\n let uuid = result?.uuid;\n\n if (isNil(uuid)) {\n uuid = uuidv4();\n\n await this.db('badges')\n .insert({\n uuid: uuid,\n name: name,\n namespace: namespace,\n kind: kind,\n })\n .onConflict(['name', 'namespace', 'kind'])\n .ignore();\n }\n\n return { uuid };\n }\n}\n"],"names":["resolvePackagePath","uuid","isNil","uuidv4"],"mappings":";;;;;;AAwCA,MAAM,aAAgB,GAAAA,gCAAA;AAAA,EACpB,4CAAA;AAAA;AAAA,EACA,YAAA;AAAA;AACF,CAAA,CAAA;AAMO,MAAM,mBAA2C,CAAA;AAAA,EAC9C,YAA6B,EAAU,EAAA;AAAV,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA,CAAA;AAAA,GAAW;AAAA,EAEhD,aAAa,MAAO,CAAA;AAAA,IAClB,QAAA;AAAA,IACA,cAAA;AAAA,GAI+B,EAAA;AAC/B,IAAM,MAAA,MAAA,GAAS,MAAM,QAAA,CAAS,SAAU,EAAA,CAAA;AAExC,IAAA,IAAI,CAAC,QAAA,CAAS,UAAY,EAAA,IAAA,IAAQ,CAAC,cAAgB,EAAA;AACjD,MAAM,MAAA,MAAA,CAAO,QAAQ,MAAO,CAAA;AAAA,QAC1B,SAAW,EAAA,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